package com.ala.config;

import com.ala.dao.DeviceMapper;
import com.ala.emqx.MqttGateway;
import com.ala.model.EmqMessage;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class AfterServiceStarted implements ApplicationRunner {

    @Resource
    DeviceMapper deviceMapper;

    @Autowired
    MqttGateway mqttGateway;




    /**
     * 会在服务启动完成后立即执行
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {


//        int i = deviceMapper.updateOnline(0);
//
//        System.out.println("Successful service startup! "+i);
//
//        EmqMessage em = new EmqMessage();
//        em.setTopic(EmqTopics.check_online_server);
//        em.setTime(System.currentTimeMillis());
//        mqttGateway.sendToMqtt(em.getTopic(), JSON.toJSONString(em));

    }
}